package units.vessels 
{
	import base.*;
	import appkit.responders.NResponder;
	import control.Action;
	import flash.events.Event;
	import tweens.Tween;
	
	public class Vessel extends GObject 
	{
		
		private var path:Vector.<GPoint>;
		public var actions:Vector.<Action>;
		
		public function on_enterframe(e:Event):void
		{
			if (path.length > 0)
				move( path.pop());
			else
				NResponder.remove(Event.ENTER_FRAME, on_enterframe);
		}
		
		public function move(point:GPoint):void
		{
			turn(GPoint.degrees( new GPoint(this.x - point.x, this.y - point.y).angle()));
			var t:Tween = new Tween(this, { x: { start:this.x, end:point.x, steps:15 }, y: { start:this.y, end:point.y, steps:15 }}, Tween.circleInOut);
			t.start();
		}
		
		public function turn(deg:Number):void
		{
			var t:Tween = new Tween(this, { rotation: { start:this.rotation, end:deg + 90, steps:10 }}, Tween.circleInOut);
			t.start();
		}
		
		public function pop():GPoint
		{
			if (path.length > 0)
				return path[0];
			return null;
		}
		
		public function add(point:GPoint):void
		{
			path.push(point);
			if (!NResponder.has(null, on_enterframe, null))
				NResponder.addNative(this, Event.ENTER_FRAME, on_enterframe, 0, .9);
		}
		
		public function Vessel(s:GShape) 
		{
			super(s);
			path = new Vector.<GPoint>();
			actions = new Vector.<Action>();
		}
		
	}

}